#!/bin/sh
uci -q batch <<-EOF >/dev/null
	set system.@system[-1].ttylogin=1
	set system.ntp.use_dhcp='0'
	set system.ntp.enable_server='1'
	commit system
	set rpcd.@rpcd[0].timeout=120
	commit rpcd
	set luci.apply.timeout='20'
	commit luci
	set fstab.@global[0].check_fs='1'
	commit fstab
EOF

if [ "$(uci -q get rpcd.@rpcd[0].socket)" != "/var/run/ubus/ubus.sock" ]; then
	uci -q batch <<-EOF >/dev/null
		set rpcd.@rpcd[0].socket='/var/run/ubus/ubus.sock'
		commit rpcd
	EOF
fi

/sbin/block detect > /etc/config/fstab

[ -n "$(ubus call system board | jsonfilter -e '@.board_name' | grep raspberry)" ] && [ "$(uci -q get openmptcprouter.settings.scaling_governor)" != "performance" ] && {
	# force CPU speed for RPI
	uci -q set openmptcprouter.settings.scaling_min_freq=$(cat /sys/devices/system/cpu/cpufreq/policy0/scaling_max_freq | tr -d "\n")
	uci -q set openmptcprouter.settings.scaling_max_freq=$(cat /sys/devices/system/cpu/cpufreq/policy0/scaling_max_freq | tr -d "\n")
	uci -q set openmptcprouter.settings.scaling_governor='performance'
	uci -q commit openmptcprouter
}

exit 0